<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" name="username" />
    <script>
      // 检测用户输入的用户名和
      document.querySelector('[name="username"]').addEventListener('keyup', function () {
        let res = this.value.match(/^[a-z]{3,6}&/i);
        console.log(res);
        console.log(res ? '正确' : '错误');
      });
    </script>
  </body>
</html>
